﻿using System.Collections.Generic;
using System.Web.Mvc;
using tophd.Models.Entity;
using tophd.Models.Service;

namespace tophd.Controllers
{
    public class VideoController : Controller
    {
        //
        // GET: /Video/

        public ActionResult Index()
        {
           

            return View();
        }

        public ActionResult DetailVideo(long videoId)
        {
            CategoryService s1 = new CategoryService();
            //List<Category> pListCate = s1.GetCategory(0);
            VideoService s = new VideoService();
           
            VideoService vs = new VideoService();
            Video video = vs.GetDetailVideo(videoId);
            List<Video> vlist = vs.GetVideo(video.CategoryId, 0, 0, 10);
            CategoryService cs = new CategoryService();
           
            vlist.Remove(video);
            ViewData["DetailVideo"] = video;
            ViewData["VideoCouldYouLike"] = vlist;
            
            return View();
        }

        public ActionResult WatchVideo(long videoId)
        {
            VideoService vs = new VideoService();
            Video video = vs.GetDetailVideo(videoId);
            CategoryService cs = new CategoryService();
            List<HotItem> lhot = cs.GetHotItem(9);
            ViewData["WatchVideo"] = video;
            ViewData["hotVideo"] = lhot;
            return View();
        }
        [HttpGet]
        public ActionResult ListVideo(string type, int page = 1)
        {
            VideoService vservice = new VideoService();
            List<Video> vlist = null;
            if (type == "new")
            {
                vlist = vservice.GetVideo(0, 0, 20 * page - 19, 20 * page); //0: moi nhat
            }
            else {
                vlist = vservice.GetVideo(0, 1, 20 * page - 19, 20 * page); //1: hot nhat
            }
            int totalRecord = 0;
            List<Video> totalVideo = vservice.GetVideo(0, 0, 0, 0);
            totalRecord = totalVideo.Count;
            //List<Video> vList = null;
            //List<Video> vList2 = null;
            //if (categoryId != null)
            //{
            //    vList = vservice.GetVideo(categoryId, 1, 4 * hotpage - 3, 4 * hotpage);
            //    vList2 = vservice.GetVideo(categoryId, 0, 4 * newpage - 3, 4 * newpage);
            //    List<Video> totalVideo2 = vservice.GetVideo(categoryId, 0, 0, 0);
            //    totalRecord = totalVideo2.Count;
            //}
            
            
            ViewData["vList"] = vlist;
            //ViewData["vList"] = vList;
            //ViewData["vList2"] = vList2;
            ViewBag.totalRecord = totalRecord;
            
            ViewBag.page = page;
            ViewBag.type = type;
            return View();
        }
    }
}
